/*
	Custom code for a ColorPickerWidget
	CSS modified version from http://jqueryui.com/demos/slider/#colorpicker
*/

function ColorPickerWidget_HexFromRGB(r, g, b) {
	var hex = [
		r.toString(16),
		g.toString(16),
		b.toString(16)
	];
	$.each(hex, function (nr, val) {
		if (val.length == 1) {
			hex[nr] = '0' + val;
		}
	});
	return hex.join('').toUpperCase();
}

function ColorPickerWidget_Refresh(slider, value_field) {
	// Update the result from sliders.

	// Update slider object.
	var red = $("#"+slider+"Red").slider("value")
		,green = $("#"+slider+"Green").slider("value")
		,blue = $("#"+slider+"Blue").slider("value")
		,hex = ColorPickerWidget_HexFromRGB(red, green, blue);
	$("#"+slider+"Swatch").css("background-color", "#" + hex);

	// Update the field.
	$("#id_"+value_field).val('rgb('+red+','+green+','+blue+')')
}
